
var BadGuy = new Class({
    Extends: Hero,
    initialize: function(){
		this.parent(GAMEUNITTYPE.MONSTER);
		game.heroes.push(this);
        this.currentDirection='left';
        this.horizontalStepsBeforeChangeDirection=4;
        this.verticalStepsBeforeChangeDirection =2;
        this.delayBeat=0; // to change speed , chnage this one
        this.cuanta = 1;
        this.dinc=2;
        this.delayBeatContor=0;
        this.deltaX=0;
        this.deltaY=0; // pixels made by the hero without any change in the direction it runs
        this.points = 50;
    },
      moveAlongDirection: function(){
      	  /// this causes the badguys to move slower than the hero
          if(this.delayBeatContor<=this.delayBeat){
              this.delayBeatContor++;
              return;
          }
          this.delayBeatContor=0;
          //////////// end slow speed timer
          this.parent();
          this.badGuyMove();
          this.killTheHero();
      },
      badGuyMove: function(){
          if(this.hitWorldBoundary==true){
              this.cuanta=this.cuanta*(-1);
              this.hitWorldBoundary=false;
          }
          if(this.hitTheWall){
          	  /////// if we hit the wall we turn back or we change direction
          	  var randy=Math.round(Math.random()*8);
              if(randy>3){
              		this.cuanta=this.cuanta*(-1); /// change the sense in the same direction - this is preferred
              } else {
	              if(this.currentDirection=='left')
	                  this.currentDirection='top';
	              else
	                  this.currentDirection='left';
              }
          } else {
	          if(this.currentDirection=='left'){
	              this.deltaX+=this.dinc;
	              if(this.deltaX>=this.horizontalStepsBeforeChangeDirection*game.standardWidth){
	                  this.deltaX=0;
	                  var randy=Math.round(Math.random()*8);
	                  if(randy>4)
	                    this.currentDirection='top';
	                    else
	                        this.cuanta=this.cuanta*(-1);
	                  this.horizontalStepsBeforeChangeDirection=Math.round(Math.random()*(game.worldWidth/game.standardWidth));
	              }
	          }
	          if(this.currentDirection=='top'){
	              this.deltaY+=this.dinc;
	              if(this.deltaY>=this.verticalStepsBeforeChangeDirection*game.standardHeight){
	                  this.deltaY=0;
	                  var randy=Math.round(Math.random()*8);
	                  if(randy>4)
	                    this.currentDirection='left';
	                else
	                    this.cuanta=this.cuanta*(-1);
	                  this.verticalStepsBeforeChangeDirection =Math.round(Math.random()*(game.worldHeight/game.standardHeight));
	              }
	          }
          }
      },
        die: function(){
            util.removeElementFromArray(this,game.heroes);
            if($defined(game.hero))
                game.hero.addPointsToScore(this.points);
        },
      killTheHero: function(){
          if($defined(game.hero)){
              if(!(game.hero.x+game.standardWidth<=this.x || game.hero.x>=this.x+game.standardWidth || game.hero.y>=this.y+game.standardHeight || game.hero.y+game.standardHeight<=this.y))
                game.hero.terminate();
          }
      }
    });